package com.yuexunit.finance.system.action.v1.dto;

import com.yuexunit.finance.system.action.v1.model.SystemParamDetail; 
import com.yuexunit.finance.system.entity.SystemParamEntity;
import com.yuexunit.finance.system.entity.lexicon.ParamTypeEnum;


/**
 * @author wenwenlong
 */
public class SystemParamDetailCastor {
	public static SystemParamEntity toSystemParamEntity(SystemParamDetail detail) {
		SystemParamEntity entity = new SystemParamEntity();
		entity.setParamId(detail.getParamId());
		entity.setParamName(detail.getParamName());
		entity.setParamType(ParamTypeEnum.valueOf(detail.getParamType()));
		entity.setParamValue(detail.getParamValue());
		entity.setRemark(detail.getRemark());
		return entity;
	}
	
	public static SystemParamDetail toSystemParamDetail(SystemParamEntity entity) {
		SystemParamDetail detail = new SystemParamDetail();
		detail.setParamId(entity.getParamId());
		detail.setParamName(entity.getParamName());
		detail.setParamType(changeType(entity.getParamType().getValue()));
		detail.setParamValue(entity.getParamValue());
		detail.setRemark(entity.getRemark());
		detail.setEnabled(entity.getEnabled());
		detail.setUpdateTime(entity.getUpdateDateTime());
		
		return detail;
	}
	
	private static Integer changeType(String type) {
		Integer num = null;
		switch (type) {
		case "字符串":
			num = 0;
			break;
		case "数值":
			num = 1;
			break;
		case "附件":
			num = 2;
			break;
		default:
			break;
		}
		return num;
	}
}
